<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>

    // 删除cookie  设置过期时间为以前的时间
    var date = new Date();
    date.setDate(-1)
    // toUTCString() 转成世界协调时间字符串
    document.cookie = "age=180;expires=" + date.toUTCString();

    function delCookie(key) {
      var date = new Date();
      date.setDate(-1) //设置过期时间为以前的时间 完成删除cookie 
      document.cookie = key + "='';expires=" + date.toUTCString();
    }

  </script>
</body>

</html>